package com.xiyue.lenovo.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by Lenovo on 2016/4/26.
 */
public class DrawView extends View {

    public float currentX=40;
    public float currentY=50;
    //定义、创建画笔
    Paint p = new Paint();
    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //设置画笔的颜色
        p.setColor(Color.RED);
        canvas.drawCircle(currentX,currentY,50,p);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        this.currentX=event.getX();
        this.currentY=event.getY();
        //通知该事件重绘
        this.invalidate();
        //返回true表明方法已经处理该事件
        return true;
    }
}
